package com.ziyueyuwen.xiniao.aop.log;

import com.alibaba.fastjson.JSON;
import com.ziyueyuwen.xiniao.bean.ZyClassLessonInfo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wancheng  on 2019/1/24.
 */
@Component
@Aspect
public class LessonLogAop {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @AfterReturning(value = "execution(* com.ziyueyuwen.xiniao.service.baseservice.lesson.impl.ZyClassLessonServiceImpl.saveLessonBatch(..))", returning = "returnValue")
    public void afterSaveLessonLog(JoinPoint joinPoint, List<ZyClassLessonInfo> returnValue) {
        Object[] obj = joinPoint.getArgs();
        List<ZyClassLessonInfo> eeoSyncSuccess = new ArrayList<>();
        Integer classId = null;
        String teacherAccount = null;
        Integer seatNum = null;
        if (obj != null) {
            eeoSyncSuccess = (List<ZyClassLessonInfo>)obj[0];
            classId = (Integer)obj[1];
            teacherAccount = (String)obj[2];
            seatNum = (Integer)obj[3];
            logger.info("批量添加 aop 日志:\neeoSyncSuccess={}\nclassId={}\nteacherAccount={}\nseatNum={}\n保存结果:{}",
                    JSON.toJSONString(eeoSyncSuccess),classId,teacherAccount,seatNum,JSON.toJSONString(returnValue));
        }
    }
}
